package com.anlu.zk.core.test;

import java.util.List;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;

public class OrderService implements Runnable {

    //发令枪，模拟50个并发
    private static CountDownLatch countDownLatch = new CountDownLatch(50);
    private static OrderNumGenerater orderNumGenerater = new OrderNumGenerater();

    private static List<String> result = new Vector<>();

    private int count;

    public OrderService(int count) {
        this.count = count;
    }

    @Override
    public void run() {
        countDownLatch.countDown();
        result.add(orderNumGenerater.getNumber(count));
    }


    public static void main(String[] args) {

        System.out.println("生成唯一的订单号");


        for (int i=0;i<50;i++){
            new Thread(new OrderService(i)).start();
        }
        try {
            countDownLatch.await();
            System.out.println("信号枪发射完成");
        }catch (Exception e){
            e.printStackTrace();
        }


    }

}
